#include "widget.h"
#include "ui_widget.h"
#include "QDebug"
#include "QButtonGroup"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    //设置姓名
    //设置隐藏内容
    ui->lineEdit_name->setPlaceholderText("请输入姓名");
    //设置一键清除按钮
    ui->lineEdit_name->setClearButtonEnabled(true);

    //设置密码
    ui->lineEdit_passward->setPlaceholderText("请输入密码");
    ui->lineEdit_passward->setClearButtonEnabled(true);
    ui->lineEdit_passward->setEchoMode(QLineEdit::Password);

    //设置电话
    ui->lineEdit_number->setPlaceholderText("请输入电话");
    ui->lineEdit_number->setClearButtonEnabled(true);
    ui->lineEdit_number->setInputMask("000-0000-0000");

    QButtonGroup* group1=new QButtonGroup(this);
    group1->addButton(ui->radioButton_male);
    group1->addButton(ui->radioButton_female);

    ui->lineEdit_XSMM->setPlaceholderText("请输入密码");
    ui->lineEdit_XSMM->setClearButtonEnabled(true);
    if(ui->radioButton->isChecked())
        ui->lineEdit_XSMM->setEchoMode(QLineEdit::Password);
    else
        ui->lineEdit_XSMM->setEchoMode(QLineEdit::Normal);
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_clicked()
{
    //如果radioButton_male按钮检测为true，则给string填“男”
    QString string=ui->radioButton_male->isChecked()?"男":"女";
    qDebug()<<"姓名："<<ui->lineEdit_name->text()
           <<"密码："<<ui->lineEdit_passward->text()
          <<"电话："<<ui->lineEdit_number->text()
         <<"性别："<<string;
}

void Widget::on_lineEdit_newmm_textEdited(const QString &arg1)
{
    compare();
}

void Widget::on_lineEdit_mm_textEdited(const QString &arg1)
{
    compare();
}

void Widget::compare()
{
    QString s1=ui->lineEdit_newmm->text();
    QString s2=ui->lineEdit_mm->text();
    if(s1!=""&&s2!=""&&s1==s2)
        ui->label_TS->setText("密码相同");
    else if(s1!=""&&s2!="")
        ui->label_TS->setText("密码不同");
    else
        ui->label_TS->setText("请输入密码");
}

void Widget::on_radioButton_toggled(bool checked)
{
    if(checked)
    {
        ui->lineEdit_XSMM->setEchoMode(QLineEdit::Password);
    }
    else
        ui->lineEdit_XSMM->setEchoMode(QLineEdit::Normal);
}
